package com.leetcode.LeetCode精选TOP面试题;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 覃国强
 * @date 2022-05-07 10:43
 */
public class 题库_0001_两数之和 {

  static
  class Solution {
    public int[] twoSum(int[] nums, int target) {
      Map<Integer, Integer> map = new HashMap<>();
      for (int i = 0; i < nums.length; ++i) {
        int value = target - nums[i];
        if (map.containsKey(value)) {
          return new int[]{map.get(value), i};
        }
        map.put(nums[i], i);
      }
      return new int[0];
    }
  }

}
